import { defineEventHandler, getQuery } from 'h3'
import axios from 'axios'

export default defineEventHandler(async (event) => {
  const query = getQuery(event)
  const apiUrl = `https://api.indtrd.com${event.req.url}` // 确保 event.req.url 包含 '/api/' 前缀
  
  try {
    const response = await axios({
      method: event.req.method,
      url: apiUrl,
      headers: {
        'Content-Type': 'application/json',
        // 如果需要，可以在这里添加其他请求头
      },
      data: query, // 如果是 POST 请求，传递请求体
    })

    return response.data // 返回 API 响应数据
  } catch (error) {
    console.error('Error in proxy:', error)
    throw createError({ statusCode: error.response?.status || 500, statusMessage: error.message })
  }
}) 